import { BaseWindow } from "../../../../component/window/BaseWindow";
import { PageTool } from "../../../../common/global/PageTool";
import { DragEvent } from "../../../../../com/mui/events/DragEvent";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { GuildEventName } from "../GuildEventName";
import { Language } from "../../../../../extend/language/Language";
import { TilePanel } from "../../equipment/TilePanel";
import { ApplyRenderer } from "./ApplyRenderer";
import { PageSelecter } from "../../common/pageSelect/PageSelecter";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { BaseItem } from "../../common/BaseItem";
import { ItemData } from "../../../resource/info/ItemData";
import { SPlayerItem } from "../../../../../Message/Public/SPlayerItem";
import { EPlayerItemPosType } from "../../../../../Message/Public/EPlayerItemPosType";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
//class ApplyListWindow
    
    export  class ApplyListWindow extends BaseWindow
    {
        constructor()
        {
            super();
            this._pageTool = new PageTool([], 5);
            this.init();
            this.addEventListener(flash.events.Event.CHANGE, this.onCurPageChangeHandler);
            this.addEventListener(DragEvent.Event_Move_In, this.onMoveInHandler);
            Dispatcher.addEventListener(GuildEventName.WarehouseSendToApply, this.onWarehouseSendToApplyHandler);
            return;
        }

        public init(): void
        {
            this.setSize(275, 360);
            this.titleHeight = 28;
            this.title = Language.getString(57241);
            this._itemListPanel = new TilePanel();
            this._itemListPanel.horizontalGap = 3;
            this._itemListPanel.verticalGap = 3;
            this._itemListPanel.setSize(245, 265);
            this._itemListPanel.columnWidth = 245;
            this._itemListPanel.rowHeight = 50;
            this._itemListPanel.setStyle("cellRenderer", ApplyRenderer);
            this._itemListPanel.move(17, 40);
            this.addChild(this._itemListPanel);
            this._pageBar = new PageSelecter();
            this._pageBar.mode = PageSelecter.SingleMode;
            this._pageBar.x = 100;
            this._pageBar.y = 307;
            this.addChild(this._pageBar);
            ObjCreate.createTextField("申请成功的物品将以邮件形式获得", 45, 330, 220, 20, this, GlobalStyle.textFormat6);
            return;
        }

        public setDefaultPage(arg1: Array<any>): void
        {
            if (arg1) 
            {
                this._pageTool.array = arg1;
            }
            this._pageBar.currentPage = 1;
            this._pageBar.maxPage = this._pageTool.pagesCount;
            this.updateItemListProvider(this._pageTool.getByPageNo(1));
            return;
        }

        public updateItemListProvider(arg1: Array<any>): void
        {
            var loc2=0;
            var loc1=new DataProvider();
            if (!(arg1 == null) && arg1.length > 0) 
            {
                loc2 = 0;
                while (loc2 < arg1.length) 
                {
                    loc1.addItem(arg1[loc2]);
                    ++loc2;
                }
                this._itemListPanel.dataProvider = loc1;
            }
            this._itemListPanel.dataProvider = loc1;
            return;
        }

        /* internal  */onCurPageChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=this._pageBar.currentPage;
            this.updateItemListProvider(this._pageTool.getByPageNo(loc1));
            return;
        }

        /* internal  */onMoveInHandler(arg1: DragEvent): void
        {
            var loc1=null;
            if (typeof arg1.dragItem === "baseitem") 
            {
                loc1 = ((arg1.dragItem as BaseItem).dragSource as ItemData).data;
            }
            this.confirmApply(loc1);
            return;
        }

        /* internal  */confirmApply(arg1: SPlayerItem): void
        {
            if (arg1 && arg1.posType == EPlayerItemPosType._EPlayerItemPosTypeGuildWarehouse) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GuildWarehouseApply, {"playerItem": arg1}));
            }
            return;
        }

        /* internal  */onWarehouseSendToApplyHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as SPlayerItem;
            this.confirmApply(loc1);
            return;
        }

        /* internal */ /* var */_titleTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_itemListPanel: TilePanel;

        /* internal */ /* var */_pageBar: PageSelecter;

        /* internal */ /* var */_pageTool: PageTool;
    }
